<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>menu</title>
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <link rel="stylesheet" href="/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">

    <style>
        .layui-btn:not(.layui-btn-lg ):not(.layui-btn-sm):not(.layui-btn-xs) {
            height: 34px;
            line-height: 34px;
            padding: 0 8px;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div>
            <table id="user-table" class="layui-table" lay-filter="user-table"></table>
        </div>
    </div>
</div>
<!-- 操作列 -->
<!-- <script type="text/html" id="auth-state">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script> -->
<script type="text/html" id="toolButton">
    <div class="layui-btn-container">
        <div class="layui-btn-group" >
            {{#  if(HavePermission('adminlist-add')){ }}
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" id="add" lay-event="add">新增<i class="layui-icon"></i></button>
            {{#  }  }}
            {{#  if(HavePermission('adminlist-update')){ }}
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" id="update" lay-event="update">修改<i class="layui-icon"></i></button>
            {{#  }  }}
            {{#  if(HavePermission('adminlist-delete')){ }}
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" id="delete" lay-event="delete">删除<i class="layui-icon"></i></button>
            {{#  }  }}
            {{#  if(HavePermission('adminlist-password')){ }}
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" id="password" lay-event="password">重置密码<i class="layui-icon"></i></button>
            {{#  }  }}
        </div>
    </div>
  </script>
  
<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8">
</script>
<script src="/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="/js/custorm/init.js"></script>
<script>
    layui.use(['table', 'table'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        initTable();
        // 渲染表格
       function renderTable(d){
            layer.load(4);
            table.render({
                elem: '#user-table',
                data: d,
                page: true,
                limit: 15,
                cellMinWidth: 80,
                toolbar: '#toolButton',
                cols: [[
                    {type: 'checkbox', fixed: 'left'},
                    {type: 'numbers', fixed: 'left'},
                    { field: 'id', title: 'ID', align: 'center' },
                    { field: 'loginName', title: '登录名', align: 'center' },
                    { field: 'userName', title: '用户名', align: 'center' },
                    { field: 'rolename', title: '角色', align: 'center' },
                    {  field: 'sex', width: 80, align: 'center', templet: function (d) {
                        if (d.sex) {
                            return '<span >男</span>';
                        }
                        else{
                            return '<span >女</span>';
                        }
                    }, title: '性别' },  
                    { field: 'phone', title: '电话', align: 'center' },
                    { field: 'address', title: '地址', align: 'center' },
                    {  field: 'status', width: 100, align: 'center', templet: function (d) {
                        if (d.status) {
                            return '<span >正常</span>';
                        }
                        else{
                            return '<span >禁用</span>';
                        }
                    }, title: '状态' },  
                ]], done: function (res, curr, count) {
                    layer.closeAll('loading');
                }
            });
        }
       // AxajGet('../api/home/GetAllUser','../../login.html',renderTable);
      function initTable(){
        AxajGet('../api/sys/GetAllUser','../../login.html',renderTable);
      }
          //头工具栏事件
        table.on('toolbar(user-table)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
            case 'add':
                window.location.href="user/add.html";
            break;
            case 'update':
                var data = checkStatus.data;
                if(data.length!=1){
                    layer.msg("请选择一条数据");
                    return;
                }
                window.location.href="user/edit.html?id="+data[0].id;
            break;
            case 'delete':
                var data = checkStatus.data;
                if(data.length==0){
                    layer.msg("请选择一条数据");
                    return;
                }
                AxajPost('../api/sys/DeleteUser',data,'删除成功','../../login.html',initTable);
                
            break;
            case 'password':
                var data = checkStatus.data;
                if(data.length!=1){
                    layer.msg("请选择一条数据");
                    return;
                }
                console.log(data[0].id);
                AxajPost('../api/sys/ResetUserPassword?id='+data[0].id,null,'重置成功','../../login.html',initTable);
                
            break;
            //自定义头工具栏右侧图标 - 提示
            case 'LAYTABLE_TIPS':
                layer.alert('这是工具栏右侧自定义的一个图标按钮');
            break;
            };
        });

    });
</script>
</body>
</html>